package org.dejlis.kurzycnb;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.DatePicker;

public class MainActivity extends Activity {
	public static final String EXTRA_URL = "org.dejlis.kurzycnb.extra_url";
	public static final String URL_PREFIX = "http://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.txt?date=";
	public String displayString;
	 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void fetchRates(View view){
		DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
		int day = datePicker.getDayOfMonth();
		int month = datePicker.getMonth();
		int year = datePicker.getYear();
		String date = Integer.toString(day) + "." + Integer.toString(month) + "." + Integer.toString(year);
		
		// fetch the Rates
		String url = URL_PREFIX + date;

		Intent intent = new Intent(this, DisplayRatesActivity.class);

		intent.putExtra(EXTRA_URL, url);				
								
    	startActivity(intent);		
	}

	



	
}
